Ext.namespace("Doc");

Doc.Feedback = function (p){
	this.parentWin=p
	this.winMsg=null;
	thiz=this;
	
	this.txtRemind=new Ext.form.Hidden({name:'remind'});
	this.txtNum = new Ext.form.TextField({
        fieldLabel: '公文编号',
        name:'docNum',
        disabled:true,
        width: 120
    });
    this.hdSuperviseId = new Ext.form.Hidden({name:'superviseId'});
    this.hdAuditId = new Ext.form.Hidden({name:'auditId'});
	this.txtTitle = new Ext.form.TextField({
        fieldLabel: '公文名称',
        name:'superviseTitle',
        width: 340,
        disabled:true
    });
	this.txtManagerId=new Ext.form.Hidden({name:'managerId'});
	this.txtManagerName = new Ext.form.TextField({
		fieldLabel: '阅处负责人',
		name:'managerName',
		width: 120,
		disabled: true
	});
	this.txtIssueDate = new Ext.form.TextField({
    	fieldLabel: '批示日期',
    	name:'issueDate',
		disabled:true,
		width:120
	});
	
	this.txtIssueType = new Ext.form.ComboBox({
		width: 120,
		fieldLabel: '公文类别',
		name:'issueType',
        store: new Ext.data.ArrayStore({
        	fields: ['value', 'name'],
        	data: OMS.DOC_TYPE2
        }),
        valueField: 'value',
        displayField: 'name',
        disabled:true,
        mode: 'local',
        triggerAction: 'all'
	});	
	this.txtNotion = new Ext.form.TextArea({
		fieldLabel: '领导批示意见',
		name:'notion',
		width: 550,
		disabled:true,
		height: 35
	});
	this.txtFeedback = new Ext.form.TextArea({
		fieldLabel: '反馈情况',
		name:'feedback',
		width: 540,
		height: 50,
		maxLength:1000
	});
	this.btnSave = new Ext.Button({
    	text:'保存',
    	handler:this.onSave,
    	scope: this
    });
	this.form = new Ext.form.FormPanel({
		bodyStyle: 'padding: 5px 5px 0',
        frame:true,
        labelWidth: 70,
		labelAlign:'right',
		region:'north',	
		height: 160,	
		split:true,
		collapsible: true,
		items:[this.txtManagerId,this.hdAuditId,this.hdSuperviseId,
        	{ layout: 'column', border: false, defaults: {layout: 'form', border: false},
	        	items: [ { columnWidth: .66, items: [this.txtTitle]},
	        			 { columnWidth: .33, items: [this.txtNum] }]
	    },{ layout: 'column', border: false, defaults: {layout: 'form', border: false},
	        	items: [ { columnWidth: .33, items: [this.txtIssueType] },
	        			{ columnWidth: .33, items: [this.txtManagerName]},
	        	         { columnWidth: .33, items: [this.txtIssueDate]}]
	    },this.txtNotion,this.txtFeedback]
	});
	
	this.store = new Ext.data.JsonStore({
	    url: '../superviseDoc/listFeedback2.form?timesnap=' + Date.parse(new Date()),
	    root: 'result',
	    totalProperty: 'total',
        remoteSort: true,
	    fields: ['taskExeId','taskExeUpdateDate','taskId','taskExeUserId','taskExePerformType',
	    'taskExeDispatcherId','taskExeStatus','taskExePercent','taskExeBackStatus','content',
	    'taskExeUserName']
	});
	//this.store.setDefaultSort('taskFeedbackId', 'desc');
	this.renderTaskStatus = function(value){
		return OMS.TASKSEXESTATUS[value];
	}
	this.renderSend = function(value){
		return '<a href="javascript:thiz.onSendMsg('+value+')">催办</a>';
	}
	this.columns =  [
	    {header: '执行表ID', sortable: true, align: 'right',width: 20,hidden:true,dataIndex: 'taskExeId'},
	    {header: '负责人ID', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'taskExeUserId'},
	    {header: '执行人', sortable: true, align: 'center',width: 20,dataIndex: 'taskExeUserName'},
		{header: '更新日期', sortable: true, align: 'right',width: 20,dataIndex: 'taskExeUpdateDate'},
		{header: '对应ID', sortable: true, align: 'right',width: 20,hidden:true,dataIndex: 'taskId'},		
		{header: '执行类型', sortable: true, align: 'right',width: 20,hidden:true,dataIndex: 'taskExePerformType'},
		{header: '派送人', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'taskExeDispatcherId'},
		{header: '完成状态', sortable: true, align: 'right',width: 20,dataIndex: 'taskExeStatus',renderer:this.renderTaskStatus},
		{header: '完成百分比', sortable: true, align: 'right',width: 20,hidden:true,dataIndex: 'taskExePercent'},
		{header: 'TASK_EXE_BACK_STATUS', sortable: true, align: 'right',hidden:true,width: 20,dataIndex: 'taskExeBackStatus'},
		{header: '意见内容', sortable: true, align: 'center',dataIndex: 'content'},
		{header: '操作', align: 'center',width: 10,dataIndex: 'taskExeUserId',renderer:this.renderSend}
	];
	
	this.grid = new Ext.grid.EditorGridPanel({
		title:'公文反馈情况',
		region: 'center',
		cm: new Ext.grid.ColumnModel(this.columns),
		store:this.store,
		height: 170,
		autoScroll: true,
		clicksToEdit:1,
		viewConfig: { forceFit: true },
        collapsible:true
	});	
	Doc.Feedback.superclass.constructor.call(this,{
		title: '公文督办反馈',
		width:700,
		height:420,
		resizable: false,
        modal: true,
        autoScroll: true,
		closeAction:'hide',
		items:[this.form, this.grid],
		buttonAlign:'center',
		buttons:[this.btnSave,{
            text: '关闭',
            scope: this,
            handler: function() {
	        	this.hide();
        	}
        }]
	});	
};

Ext.extend(Doc.Feedback, Ext.Window, {
	initWin:function(data){
		//alert(data.auditId);
		//alert(Ext.util.JSON.encode(data));	
		this.form.getForm().setValues(data);
		this.grid.store.load({
			params:{auditId:data.auditId}
		});	
	},	
	onSave: function() {
		if(!this.form.getForm().isValid()){
			Utils.info2("有必填项没有填写，请检查！",180);
			return;
		}
		var conn = new Ext.data.Connection({
  			url:'../superviseDoc/feedbackAudit.form?timesnap=' + Date.parse(new Date()),
  			method:'post'
  		})
  		var param={superviseId:this.hdSuperviseId.getValue(),
  					auditId:this.hdAuditId.getValue(),
  					feedback:this.txtFeedback.getValue()};
  		//alert(Ext.util.JSON.encode(param));		
		Utils.request(conn,{
  			params:param,
  			scope:this,
  			success:function(data){
  				Utils.info2();
				this.scope.hide();
				this.scope.parentWin.queryDoc();
  			}
  		});
	},
	onSendMsg:function(value){		
		scope=this;
		if(this.winMsg==null)
			this.winMsg=new Message.Msg(function(){
				scope.txtRemind.setValue(scope.winMsg.txtRemind);
				scope.sendMsg(value);
			},'你确实要催办吗？');
		this.winMsg.show();
	},
	sendMsg:function(value){
		var conn = new Ext.data.Connection({
  			url:'../superviseDoc/taskMsg.form?timesnap=' + Date.parse(new Date()),
  			method:'post'
  		})
  		var param={'userId':value,auditId:this.hdAuditId.getValue(),
  					'remind':this.txtRemind.getValue()};
  		//alert(Ext.util.JSON.encode(param));		
		Utils.request(conn,{
  			params:param,
  			scope:this,
  			success:function(data){
  				Utils.info2();
  			}
  		});
	}
});